﻿using Newtonsoft.Json;
using OurEDAFM.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace OurEDAFM.Controllers
{
    public class HomeController : Controller
    {
        /// <summary>
        /// 获取频道列表
        /// </summary>
        /// <returns></returns>
        public ActionResult GetFM()
        {
            string result = WebClientHelper.GetJsonString("/Home/GetFM");
            List<Channel> list = JsonConvert.DeserializeObject<List<Channel>>(result);
            return View(list);
        }

        /// <summary>
        /// 随机获得某频道下的一个音乐（红心兆赫除外）
        /// Id为频道号，默认进入应用为私人兆赫，id为1
        /// </summary>
        /// <param name="id">频道号</param>
        /// <returns></returns>
        public string GetMusic(int id,string userToken = "")
        {
            string result = WebClientHelper.GetJsonString("/Home/GetMusic?id=" + id + "&usertoken="+userToken);
            return result;
        }

        /// <summary>
        /// 随机获取用户的一首红心歌曲
        /// </summary>
        /// <param name="id">用户ID</param>
        /// <returns></returns>
        public string GetLikeMusic(string id)
        {
            string result = WebClientHelper.GetLikeSong(id);
            return result;
        }

        /// <summary>
        /// 获取红心歌曲列表
        /// </summary>
        /// <param name="id">用户Id</param>
        /// <returns></returns>
        public string GetLike(string id)
        {
            string result = WebClientHelper.GetJsonString("/Home/GetLike?id=" + id);
            return result;
        }

        /// <summary>
        /// 添加红心音乐
        /// </summary>
        /// <param name="id">歌曲Id</param>
        /// <param name="UserToken">用户Id</param>
        /// <returns></returns>
        public string AddLike(int id, string UserToken)
        {
            var result = WebClientHelper.GetJsonString("/Home/AddLike?id=" + id + "&UserToken=" + UserToken);
            return result;
        }

        /// <summary>
        /// 给某人添加不喜欢歌曲
        /// </summary>
        /// <param name="id">歌曲ID</param>
        /// <param name="UserToken">用户ID</param>
        /// <returns></returns>
        public string AddUnLike(int id, string UserToken)
        {
            var result = WebClientHelper.GetJsonString("/Home/AddUnLike?id=" + id + "&UserToken=" + UserToken);
            return result;
        }

        /// <summary>
        /// 删除红心ID (取消喜欢)
        /// </summary>
        /// <param name="id">用户Id</param>
        /// <param name="SongID">歌曲Id</param>
        /// <returns></returns>
        public string DeleteLikeMusic(string id, int SongID)
        {
            var result = WebClientHelper.GetJsonString("/Home/DeleteLikeMusic?id=" + id + "&SongID=" + SongID);
            return result;
        }

        /// <summary>
        /// 获取歌曲的封面
        /// </summary>
        /// <param name="id">歌曲Id</param>
        /// <returns></returns>
        public string GetCorver(int id)
        {
            var result = WebClientHelper.GetJsonString("/Home/GetCorver?id=" + id);
            return result;
        }
    }
}